package com.hnhcyy.goods.pojo;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hnhcyy.b2b.common.util.DateUtil;

/**
 * 商品库存
 *
 * @author sheyongjun
 * @date 2019年2月15日
 */
public class SpBal implements Serializable {

    private static final long serialVersionUID = 7129205599948920504L;

    /**
     * ID号,和时间相关
     */
    private Integer fid;

    /**
     * 商家ID
     */
    private Integer sjid;

    /**
     * 商品ID
     */
    private String spid;

    /**
     * 批号
     */
    private String pihao;

    /**
     * 保质期,有效期开始
     */
    private Date baozhiqi;

    /**
     * 失效日期,有效期至
     */
    private Date sxrq;

    /**
     * 可销数量
     */
    private Double kxshl;

    /**
     * 是否近效期
     */
    private Boolean recent;

    @JsonInclude(Include.NON_NULL)
    public Integer getFid() {
        return fid;
    }

    public void setFid(Integer fid) {
        this.fid = fid;
    }

    @JsonInclude(Include.NON_NULL)
    public Integer getSjid() {
        return sjid;
    }

    public void setSjid(Integer sjid) {
        this.sjid = sjid;
    }

    @JsonProperty(value = "spid") // 序列化的时候要求，规则的名称
    @JsonInclude(Include.NON_NULL)
    public String getSpid() {
        return spid;
    }

    @JsonProperty(value = "FMatNumber") // 反序列化的时候key名不规则
    public void setSpid(String spid) {
        this.spid = spid;
    }

    @JsonProperty(value = "pihao")
    @JsonInclude(Include.NON_NULL)
    public String getPihao() {
        return pihao;
    }

    @JsonProperty(value = "FLotNo")
    public void setPihao(String pihao) {
        this.pihao = pihao;
    }

    @JsonProperty(value = "baozhiqi")
    @JsonInclude(Include.NON_NULL)
    public Date getBaozhiqi() {
        return baozhiqi;
    }

    @JsonProperty(value = "FProduceDate")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = CustomJsonDateDeserializer.class)
    public void setBaozhiqi(Date baozhiqi) {
        this.baozhiqi = baozhiqi;
    }

    @JsonProperty(value = "sxrq")
    @JsonInclude(Include.NON_NULL)
    public Date getSxrq() {
        return sxrq;
    }

    @JsonProperty(value = "FExpiryDate")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = CustomJsonDateDeserializer.class)
    public void setSxrq(Date sxrq) {
        this.sxrq = sxrq;
    }

    @JsonProperty(value = "kxshl")
    @JsonInclude(Include.NON_NULL)
    public Double getKxshl() {
        return Math.max(0, kxshl);
    }

    @JsonProperty(value = "FQty")
    public void setKxshl(Double kxshl) {
        this.kxshl = kxshl;
    }

    public void setRecent(Boolean recent) {
        this.recent = recent;
    }

    @JsonInclude(Include.NON_NULL)
    public Boolean getRecent() {
        if (sxrq != null && baozhiqi != null) {
            int expireDay = DateUtil.dateCompare(sxrq, baozhiqi);//失效时间-生产日期
            int remainDay = DateUtil.dateCompare(sxrq, Calendar.getInstance().getTime());//失效时间-当前时间
            if ((expireDay > 365 && remainDay < 270) || (expireDay < 365 && remainDay < 150)) {
                return true;
            }
        }
        return false;
    }

	/*public static void main(String[] args) throws ParseException {
		Spbal spbal = new Spbal();
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		spbal.setBaozhiqi(format.parse("2016-01-01 00:00:00"));
		spbal.setSxrq(format.parse("2019-01-01 00:00:00"));
		System.out.println(spbal.getRecent());
	}*/
}
